<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>类式组件state简写形式</title>
</head>
<body>
<div id="app"></div>
<script src="../lib/babel.min.js"></script>
<script src="../lib/react.development.js"></script>
<script src="../lib/react-dom.development.js"></script>
<script type="text/babel">
  class Weather extends React.Component {
    constructor(props) {
      super(props);
      /*this.state = {
        isHot: false
      }*/
    }

    state = {
      isHot: false
    }

    render() {
      return (
        <h2 onClick={this.changeHot}>今天天气很{this.state.isHot ? 'Hot' : 'cold'}</h2>
      )
    }

    // 方法使用箭头函数，避免this指向问题
    changeHot = () => {
      const {isHot} = this.state
      this.setState({
        isHot: !isHot
      })
    }
  }

  ReactDOM.render(<Weather/>, document.getElementById('app'))

</script>
</body>
</html>
